<script type="text/javascript" language="javascript">
	var http_request = false;
	var prefs = new gadgets.Prefs();
	var numTweets = prefs.getInt("numTweets");
	
	function genTwitterURL() {
		return "http://twitter.com/statuses/friends_timeline.xml?count="+numTweets;
	}

	//Given some data parsed from a tweet, generate the html to display the tweet
	function tweetToDiv(name,replyto,body,time) {
		return "<div>"+name+": "+body+"</div>";
	}
	
	function parseTwitterXML(xmldoc) {
		var tweets = xmldoc.getElementsByTagName('status');
		var content = "";
	
		for (var iTweet = 0; iTweet < tweets.length; iTweet++) {
			alert('4');
			var tweet = tweets.item(iTweet);
			var tweetdata = tweet.childNodes;
			//Populate the relevant attributes of the tweet
			var timestamp 	= tweetdata.item(0).nodeValue; //Fri Jan 30 22:59:21 +0000 2009
			var id 			= tweetdata.item(1).nodeValue; //tweet id
			var body 		= tweetdata.item(2).nodeValue; //message body
			var replyto 	= tweetdata.item(8).nodeValue; //the screenname
			var userdata 	= tweetdata.item(9).childNodes;
			var uid 		= userdata.item(0).nodeValue; //Poster's user id
			var uname		= userdata.item(1).nodeValue; //Poster's name
			var uscreenname = userdata.item(2).nodeValue; //Poster's screenname
			
			content = content + tweetToDiv(uname,replyto,body,timestamp) + "\n";
		}
		var div = document.getElementById('content_div');
		div.innerHTML = content;
	}
	
	function do_xml() {
		var params = {};
		params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.DOM;
		gadgets.io.makeRequest(genTwitterURL(), parseTwitterXML, params);
	}
</script>

<input type="button" name="button" value="Refresh" 
   onclick="javascript:do_xml();">
<br><br>
<div id="content_div"></div>